package com.kasax.skin.support;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * 皮肤缓存类
 */
public class SkinPreference {
    private static final String SKIN_SHARED = "skins";
    private static final String KEY_SKIN_PATH = "skin_path";
    private static SkinPreference instance;
    private final SharedPreferences sharedPreferences;

    private SkinPreference(Context context) {
        sharedPreferences = context.getSharedPreferences(SKIN_SHARED, Context.MODE_PRIVATE);
    }

    public static void init(Context context) {
        if (instance == null) {
            synchronized (SkinResource.class) {
                if (instance == null) {
                    instance = new SkinPreference(context.getApplicationContext());
                }
            }
        }
    }

    public static SkinPreference getInstance() {
        return instance;
    }

    /**
     * 保存皮肤
     *
     * @param path
     */
    public void saveSkin(String path) {
        sharedPreferences.edit().putString(KEY_SKIN_PATH, path).apply();
    }

    /**
     * 获取皮肤
     *
     * @return
     */
    public String getSkin() {
        return sharedPreferences.getString(KEY_SKIN_PATH, null);
    }
}
